package com.juicygames.framework.property.space;

import com.juicygames.framework.action.UpdateAction;
import com.juicygames.framework.gamepart.GameHandler;
import com.juicygames.framework.property.GameProperty;
import com.juicygames.framework.type.Point;

public class Velocity extends GameHandler<UpdateAction> implements GameProperty<Point> {
	
	private Point velComponents;
	
	private Position entityPosition;
	
	public Velocity(Point value) {
		super();
		velComponents = value;
	}
		
	public void load() {
		groundHandler();
		
		entityPosition = parent.getPart(Position.class);
	}
	
	public Class<UpdateAction> getActionClassHandled() {
		return UpdateAction.class;
	}
	
	public Velocity() {
		this(new Point(0,0));
	}
	
	public void stop() {
		velComponents.x = 0;
		velComponents.y = 0;
	}
	
	public void handle(UpdateAction action) {
		entityPosition.get().offset(velComponents);
	}

	public Point get() {
		return velComponents;
	}

	public GameProperty<Point> set(Point value) {
		velComponents = value;
		return this;
	}
	
	public String toString() {
		return String.format("Velocity[%d,%d]", velComponents.x, velComponents.y);
	}

}
